package com.cqc.propertyanimatordemo;

import android.animation.Animator;
import android.animation.AnimatorInflater;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator.AnimatorUpdateListener;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;

public class MainActivity extends Activity {
	private ImageView iv;
	private Context context;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		context = this;
		iv = (ImageView) findViewById(R.id.iv);
	}

	// TranslationX 沿X轴移动
	public void click1(View view) {
		ObjectAnimator oa1 = ObjectAnimator.ofFloat(iv, "TranslationX", 0, 50,
				20, 0, 90);
		oa1.setDuration(1000);
		oa1.start();
	}

	// scaleX： X轴(宽度)缩放，Y轴(高度)不变 -2表示先缩放到0(消失)，然后到2倍大小
	public void click2(View view) {
		ObjectAnimator oa1 = ObjectAnimator.ofFloat(iv, "scaleX", 1, 3, 1, 3,
				5, -2);
		oa1.setDuration(5000);
		oa1.start();
	}

	public void click3(View view) {
		ObjectAnimator oa1 = ObjectAnimator.ofFloat(iv, "Alpha", 1.0f, 0.5f, 0,
				1.0f);
		oa1.setDuration(5000);
		oa1.start();
	}

	public void click4(View view) {
		ObjectAnimator oa1 = ObjectAnimator.ofFloat(iv, "rotationX", 100, 200,
				300, 300, 0);
		oa1.setDuration(1000);
		oa1.start();
	}

	public void click5(View view) {
		AnimatorSet set = new AnimatorSet();

		ObjectAnimator oa1 = ObjectAnimator.ofFloat(iv, "scaleX", 1, 3, 1, 3,
				5, -2);
		ObjectAnimator oa2 = ObjectAnimator.ofFloat(iv, "scaleX", 1, 3, 1, 3,
				5, -2);
		ObjectAnimator oa3 = ObjectAnimator.ofFloat(iv, "Alpha", 1.0f, 0.5f, 0,
				1.0f);
		ObjectAnimator oa4 = ObjectAnimator.ofFloat(iv, "rotationX", 100, 200,
				300, 300, 0);

		set.setTarget(iv);
		set.setDuration(1000);//

		// set.playSequentially(oa1,oa2,oa3,oa4);//一次执行动画
		set.playTogether(oa1, oa2, oa3, oa4);// 一起执行动画
		set.start();
	}

	public void click6(View view) {
		ObjectAnimator oa = (ObjectAnimator) AnimatorInflater.loadAnimator(
				context, R.animator.translate);
		oa.setTarget(iv);
		oa.start();
	}

	public void click7(View view) {
		ObjectAnimator oa = (ObjectAnimator) AnimatorInflater.loadAnimator(
				context, R.animator.scale);
		oa.setTarget(iv);
		oa.start();
	}

	public void click8(View view) {
		ObjectAnimator oa = (ObjectAnimator) AnimatorInflater.loadAnimator(
				context, R.animator.rotate);
		oa.setTarget(iv);
		oa.start();
	}

	// ObjectAnimator继承自Animator,而不是Animation，所以吧不能采用view.startAnimation(objectAnimator)
	public void click9(View view) {
		ObjectAnimator oa = (ObjectAnimator) AnimatorInflater.loadAnimator(
				context, R.animator.alpha);
		oa.setTarget(iv);
		oa.start();
	}

	public void click10(View view) {
		AnimatorSet set = (AnimatorSet) AnimatorInflater.loadAnimator(context,
				R.animator.set);
		set.setTarget(iv);
		set.start();
	}

}
